VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsLop"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private m_sMaLop As String
Private m_sMaNganh As String
Private m_sTenLop As String
Private m_sKhoa As String

Public Property Get malop() As String
    malop = m_sMaLop
End Property

Public Property Let malop(ByVal sMaLop As String)
    m_sMaLop = sMaLop
End Property

Public Property Get MaNganh() As String
    MaNganh = m_sMaNganh
End Property

Public Property Let MaNganh(ByVal sMaNganh As String)
    m_sMaNganh = sMaNganh
End Property

Public Property Get tenlop() As String
    tenlop = m_sTenLop
End Property

Public Property Let tenlop(ByVal sTenLop As String)
    m_sTenLop = sTenLop
End Property

Public Property Get khoa() As String
    khoa = m_sKhoa
End Property

Public Property Let khoa(ByVal sKhoa As String)
    m_sKhoa = sKhoa
End Property

'---------------------------------------------------------------------------------------
' Procedure : TimKiemLop
' Date      : 30/10/2011
' Purpose   : Tim kiem lop
'---------------------------------------------------------------------------------------
Public Function TimKiem(ByVal malop As String, ByVal tenlop As String, ByVal MaNganh As String, ByVal khoa As String) As ADODB.Recordset
   On Error GoTo TimKiemLop_Error
    Dim sql As String
    
    sql = "SELECT l.*, TenNganh FROM LOP l, Nganh ng " & _
                                         "WHERE MaLop = " & IIf(malop <> "", "'" & malop & "'", "MaLop") & " AND " & _
                                               "TenLop = " & IIf(tenlop <> "", "'" & tenlop & "'", "TenLop") & " AND " & _
                                               "l.MaNganh = " & IIf(MaNganh <> "", "'" & MaNganh & "'", "l.MaNganh") & " AND " & _
                                               "Khoa = " & IIf(khoa <> "", "'" & khoa & "'", "Khoa") & " AND " & _
                                               "l.MaNganh = ng.MaNganh"
    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set TimKiem = g_ObjADOConn.Execute(sql)

   On Error GoTo 0
   Exit Function
TimKiemLop_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure TimKiemLop of Class Module clsLop"
End Function

'---------------------------------------------------------------------------------------
' Procedure : SelectAll
' Date      : 27/10/2011
' Purpose   : Load danh sach tat ca record cua table co trong file du lieu
'---------------------------------------------------------------------------------------
Public Function SelectAll() As ADODB.Recordset
   On Error GoTo SelectAll_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectAll = g_ObjADOConn.Execute("SELECT mh.*, TenNganh FROM Lop mh, Nganh ng WHERE mh.MaNganh = ng.MaNganh")

   On Error GoTo 0
   Exit Function
SelectAll_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectAll of Class Module clsLop"
End Function

'---------------------------------------------------------------------------------------
' Procedure : SelectByID
' Date      : 27/10/2011
' Purpose   : Lay record cua table ung voi ma Lop truyen vao
'---------------------------------------------------------------------------------------
Public Function SelectByID(ByVal ID As String) As ADODB.Recordset
   On Error GoTo SelectByID_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectByID = g_ObjADOConn.Execute("SELECT mh.*, TenNganh FROM Lop mh, Nganh ng WHERE mh.MaNganh = ng.MaNganh AND MaLop = '" & ID & "'")

   On Error GoTo 0
   Exit Function
SelectByID_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectByID of Class Module clsLop"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Insert
' Date      : 27/10/2011
' Purpose   : Them 1 record moi vao table trong file du lieu
'---------------------------------------------------------------------------------------
Public Function Insert(ByVal ObjLop As clsLop) As Boolean
    
   On Error GoTo Insert_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("INSERT INTO Lop(MaLop, MaNganh, TenLop, Khoa) " & _
                          "VALUES('" & ObjLop.malop & "', '" & ObjLop.MaNganh & "', '" & ObjLop.tenlop & "', '" & ObjLop.khoa & "')")
    Call CloseConnection
    Insert = True
    
   On Error GoTo 0
   Exit Function
Insert_Error:
    Insert = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Insert of Class Module clsLop"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Delete
' Date      : 27/10/2011
' Purpose   : Xoa 1 record cua table trong file du lieu
'---------------------------------------------------------------------------------------
Public Function Delete(ByVal ID As String) As Boolean
   On Error GoTo Delete_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("DELETE FROM Lop WHERE MaLop='" & ID & "'")
    Call CloseConnection
    Delete = True
    
   On Error GoTo 0
   Exit Function
Delete_Error:
    Delete = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Delete of Class Module clsLop"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Update
' Date      : 27/10/2011
' Purpose   : Update record cua table dua tren ID truyen vao
'---------------------------------------------------------------------------------------
Public Function Update(ByVal ObjLop As clsLop) As Boolean
   On Error GoTo Update_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("UPDATE Lop " & _
                          "SET TenLop = '" & ObjLop.tenlop & "', " & _
                              "Khoa = '" & ObjLop.khoa & "' " & _
                          "WHERE MaLop = '" & ObjLop.malop & "'")
    Call CloseConnection
    Update = True

   On Error GoTo 0
   Exit Function
Update_Error:
    Update = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Update of Class Module clsLop"
End Function


